import store from '../store/store'
import {
  storeBindingsBehavior
} from 'mobx-miniprogram-bindings'

// custom-tab-bar/index.js
Component({
  behaviors: [storeBindingsBehavior],
  storeBindings: {
    store,
    fields: {
      tabBarActiveIndex: 'tabBarActiveIndex'
    },
    actions: {
      updateTabBarActiveIndex: 'updateTabBarActiveIndex'
    }
  },
  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    active: 0,
    "list": [{
        "pagePath": "/pages/home/home",
        "text": "首页",
        "iconPath": "/assets/img/tabs/home.png",
        "selectedIconPath": "/assets/img/tabs/home-active.png"
      },
      {
        "pagePath": "/pages/message/message",
        "text": "消息",
        "iconPath": "/assets/img/tabs/message.png",
        "selectedIconPath": "/assets/img/tabs/message-active.png"
      },
      {
        "pagePath": "/pages/contant/contant",
        "text": "联系我们",
        "iconPath": "/assets/img/tabs/contact.png",
        "selectedIconPath": "/assets/img/tabs/contact-active.png"
      }
    ]
  },

  /**
   * 组件的方法列表
   */
  methods: {
    onChange(event) {
      // event.detail 的值为当前选中项的索引
      this.updateTabBarActiveIndex(event.detail)
      // 路由跳转
      wx.switchTab({
        url: this.data.list[event.detail].pagePath,
      })
    },
  }
})